﻿using System;
using System.Linq;
using Basmus.ReadWrite;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Basmus.Tests.ReadWrite
{
    [TestClass()]
    public class BooleanReaderWriterTest
    {
        [TestMethod()]
        public void ReadTrueSuccessTest()
        {
            var target = new BooleanReaderWriter();
            var strings = new[] {"True", "true"};
            var expected = ReadResult<bool>.Success(true);

            var actuals = strings.Select(target.Read);

            Assert.IsTrue(actuals.All(x => x.Equals(expected)));
        }

        [TestMethod()]
        public void ReadFalseSuccessTest()
        {
            var target = new BooleanReaderWriter();
            var strings = new[] {"False", "false"};
            var expected = ReadResult<bool>.Success(false);

            var actuals = strings.Select(target.Read);

            Assert.IsTrue(actuals.All(x => x.Equals(expected)));
        }

        [TestMethod()]
        public void ReadTrueErrorTest()
        {
            var target = new BooleanReaderWriter();
            var strings = new[] { "1", "asdf" };
            var expected = ReadResult<bool>.Error();

            var actuals = strings.Select(target.Read);

            Assert.IsTrue(actuals.All(x => x.Equals(expected)));
        }

        [TestMethod()]
        public void ReadFalseErrorTest()
        {
            var target = new BooleanReaderWriter();
            var strings = new[] { "0", "asdf" };
            var expected = ReadResult<bool>.Error();

            var actuals = strings.Select(target.Read);

            Assert.IsTrue(actuals.All(x => x.Equals(expected)));
        }

        [TestMethod()]
        public void WriteFalseTest()
        {
            var target = new BooleanReaderWriter();

            var actual = target.Write(false);

            Assert.AreEqual(Boolean.FalseString, actual);
        }

        [TestMethod()]
        public void WriteTrueTest()
        {
            var target = new BooleanReaderWriter();

            var actual = target.Write(true);

            Assert.AreEqual(Boolean.TrueString, actual);
        }
    }
}
